package com.situ.day23.singleton;

//懒汉式
public class Singleton3 {
    private static volatile Singleton3 INSTANCE;

    private Singleton3() {
        System.out.println("Singleton3.Singleton3");
    }

    public synchronized void show() {
        synchronized (this) {

        }
    }

    public static Singleton3 getInstance() {
        //只有第一次是null的时候才需要加锁，其他情况是不需要加锁
        if (INSTANCE == null) {
            synchronized (Singleton3.class) {
                if (INSTANCE == null) {
                    INSTANCE = new Singleton3();
                }
            }
        }
        return INSTANCE;
    }

}
